package com.zyh.hotel.controller;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.zyh.hotel.dao.RoomDao;
import com.zyh.hotel.model.Room;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("room")
public class RoomController {

    @Resource
    RoomDao rd;
    //展示房间列表
    @PostMapping("List")
    public List<Room> List(){
        List<Room> list= rd.findAll();
        return list;

    }

    @PostMapping("delete")
    public String delete(@RequestBody String  json){
        JSONObject res = JSONObject.parse(json);
        int id = res.getInteger("id");
        rd.deleteById(id);
        return "删除成功";
    }
    @PostMapping("modify")
    public boolean modify(@RequestBody String json){
        JSONObject res = JSONObject.parse(json);
        int id =res.getInteger("id");
        String fix = res.getString("fix");
        String health = res.getString("health");
        String peo = res.getString("peo");
        String status = res.getString("status");
        String type = res.getString("type");
         rd.update(fix,health,peo,status,type,id);
        return true;
    }

}
